<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="java.util.*" %>
<%@page import="servlet.selectDeveloper" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Developer Edit</title>
</head>
<%
	selectDeveloper developer=new selectDeveloper();
	ArrayList developerList=new ArrayList();
	developerList=developer.getDeveloperList();
%> 
<body>
	<div style="width:100%">
		<%@include file="Menu.jsp" %>
	</div>
	<form name="DeveloperEdit"  method="post" action="EditDeveloper" onSubmit="return isDeveloperSelected();">
	<table>
		<tr>
			<td>Select Developer</td>
			<td><select id="developer" name="developer" onchange="showDeveloperDetail()">
					<option  value=-1>--Select--</option>
					<%
							for(int i=0;i<developerList.size();i++)
							{
						%>
							<option><%=developerList.get(i) %></option>
						<%	}		 %>
							</select>		
					
				</select>
			</td>
		</tr>
		<tr>
			<td>Name</td>
			<td><span id="loadName">
				<input type="text" name="nametxt" id="nametxt" size=20 ></input>
				</span>
				</td>
		</tr>
		<tr>
			<td>Phone</td>
			<td><span id="loadPhone">
				<input type="text" name="phonetxt" id="phonetxt" size=20 ></input>
				</span>
			</td>	
		</tr>
		<tr>
			<td>Email</td>
			<td><span id="loadEmail">
				<input type="text" name="emailtxt" id="emailtxt" size=20 ></input>
				</span>
			</td>	
		</tr>
		<tr>
			<td>Address</td>
			<td><span id="loadAddress">
				<TextArea name="address" id="addresstxt"  rows=3 cols=15 ></TextArea>
				</span>
			</td>	
		</tr>
		<tr>
			<td><input type="submit" value="Update" ></input></td>
		</tr>
	</table>
	</form>

</body>
<script language="javascript">

var xmlrequst=false;
var url,selectindex,selectdeveloper;
	function showDeveloperDetail()
	{
		xmlrequest=AjaxFunction();
	
		
		selectindex=document.getElementById("developer").selectedIndex;
	
		selectdeveloper=document.getElementById("developer").options[selectindex].text
	
		url="http://localhost:8181/PropertySite/getDeveloperDetails";
		url=url+"?dName="+selectdeveloper;
	

		if(document.getElementById("developer").options[selectindex].text=="--Select--")
		{
			
			document.getElementById("nametxt").value="";
            document.getElementById("phonetxt").value="";
            document.getElementById("emailtxt").value="";
            document.getElementById("addresstxt").value="";
            alert("Please select Developer");
		}
		else
		{    
				xmlrequest.open("GET",url,true);
				var developerData,showData;
				xmlrequest.onreadystatechange=function()
				{
					if(xmlrequest.readyState==4)
					 {
						if (xmlrequest.status==200)  
				         {  
     			               developerData=xmlrequest.responseText;
				               showData=developerData.split(":");
				               if(showData.length==1)
				                {
					                document.getElementById("developer").focus();
					                document.getElementById("nametxt").value="";
					                document.getElementById("phonetxt").value="";
					                document.getElementById("emailtxt").value="";
					                document.getElementById("addresstxt").value="";
	   			                }
		
				               else if(showData.length>1)
		            		   {
		                		   //var name=showData[1];
		                		   document.getElementById("nametxt").value=showData[1];
					                document.getElementById("phonetxt").value=showData[2];
					                document.getElementById("emailtxt").value=showData[3];
					                document.getElementById("addresstxt").value=showData[4];

					               
		                		   
		            		   }
				         }  
					 }    
			 };   
		  xmlrequest.send(null);
		}   
		
	}
	
	
	function AjaxFunction()
	{
		try
		{	xmlrequest=new XMLHttpRequest(); 	}
		catch(e)
		{
			try{
				xmlrequest=new ActiveXObject("Msxml2.XMLHTTP");
			   }
			catch(e)
			   {
				   xmlrequest=new ActiveXObject("Microsoft.XMLHTTP");
			   }	   

		}
		return xmlrequest;	
	}

	function isDeveloperSelected()
	 {
		selectindex=document.getElementById("developer").selectedIndex;
		if(selectindex==0)
		 {
			alert("please Select Developer");
			return false;
		 }
		 return true;
	 }	 
	 
	
	
</script>
</html>